<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" />
</head>
<body>

<div class="layui-container">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" id="classificationAddForm">
                <input type="hidden" name="id" value="${classification.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>分类别名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" value="${classification.name}">
                        <span class="green">注：如选择在App显示，最多可输入4个汉字。</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>图标位置</label>
                    <div class="layui-input-block">
                        <select name="position">
                            <option value="">请选择</option>
                            <c:forEach items="${iconList}" var="i">
                                <option value="${i.position}" ${classification.position==i.position?'selected':''}>${i.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>事件类型</label>
                    <div class="layui-input-block">
                        <select name="event" data-type="3">
                            <option value="" remark=" ">请选择</option>
                            <option value="${classify.url}" ${classification.event==classify.url?'selected':''}>${classify.name}</option>
                            <option value="${classifyAll.url}" ${classification.event==classifyAll.url?'selected':''}>${classifyAll.name}</option>
                        </select>
                    </div>
                </div>
                <div id="classifyDiv" style="${classification != null && classification.event=='classification' ? '' : 'display: none;'}">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>一级分类</label>
                        <div class="layui-input-block">
                            <select name="firstClass" data-type="1" data-click="10">
                                <option value="">请选择</option>
                                <c:forEach items="${firstList}" var="f">
                                    <option value="${f.id}" ${classification.firstClass==f.id?'selected':''}>${f.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>二级分类</label>
                        <div class="layui-input-block">
                            <select name="secondClass" data-type="2" data-click="20" class="secondClass">
                                <%--<option value="">请选择</option>--%>
                                <c:forEach items="${secondList}" var="s">
                                    <option value="${s.id}" ${classification.secondClass==s.id?'selected':''}>${s.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">三级分类</label>
                        <div class="layui-input-block">
                            <select name="thirdClass" class="thirdClass">
                                <%--<option value="">请选择</option>--%>
                                <c:forEach items="${thirdList}" var="t">
                                    <option value="${t.id}" ${classification.thirdClass==t.id?'selected':''}>${t.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>分类图标</label>
                    <div class="layui-input-block">
                        <label for="imgUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="imgUrl" id="imgUrl"
                               onchange="showImg(this)"/>
                        <img id="img" src="${classification.icon==null?' ':classification.icon}" width="100" height="100"/><br>
                        <span class="green">建议上传100*100尺寸大小的图片,格式支持jpg，png等</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" class="layui-input" value="${classification.sort}">
                        <span class="green">注：排序越高越靠前, (格式为:数字1-9，不能包含其他字符)</span>
                    </div>
                </div>
            </form>
            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" onclick="FormSubmit('#classificationAddForm','/icon/editClassification')">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function(){
        var $ = layui.$,layer = layui.layer,element = layui.element,form=layui.form;
        element.render();

        form.on('select',function (data) {
            var dom = data.elem;
            var selectType = $(dom).data("type");
            var clickType = $(dom).data("click");
            var id = data.value;
            if (selectType === 1){
                $.ajax({
                    url: "/classify/queryClassifyListByAjax",
                    data: {"pid": id,"type":3,"flag":2},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        $(".secondClass").append(html);
                        //重新渲染下拉框元素
                        form.render('select');
                    }
                });
            }else if(selectType === 2){
                $.ajax({
                    url: "/classify/queryClassifyListByAjax",
                    data: {"pid": id,"type":3,"flag":3},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        $(".thirdClass").append(html);
                        //重新渲染下拉框元素
                        form.render('select');
                    }
                });
            } else if (selectType === 3) {
            	if (id === 'classification') {
	            	$("#classifyDiv").show();
            	} else if (id === 'classificationAll') {
	            	$("#classifyDiv").hide();
            	}
            }
            if(clickType === 10){
                $(".secondClass").empty();
                $(".thirdClass").empty();
            }else if(clickType === 20){
                $(".thirdClass").empty();
            }
        })
    });
</script>
</body>
</html>